#include "server.hpp"
#define HOST "127.0.0.1"
//#define PORT 3306
#define PORT 7306
#define USER "root"
//#define PASSWORD "XyK@71986582"
#define PASSWORD "qsy@71986582"
#define DB "gobang"
void testLog()
{
    // LOG("%s-%d\n","hello log",10);
    // printf("%s" "%d\n","sdfa",10);
    // LOG("lashfa");
    ILOG("info");
    DLOG("debug");
    ELOG("error");
}
void testMySQL()
{
    MYSQL *mysql = mysql_util::mysql_create(HOST, USER, PASSWORD, DB, PORT);
    string insert = "insert stu values(null,'小明',17,99,125,63.5),(null,'小黑',17,77,128.5,73.5);";
    mysql_util::mysql_exec(mysql, insert);
    mysql_util::mysql_destroy(mysql);
}
void testJson()
{
    // 将数据储存到Json::Value对象中
    Json::Value root;
    string out;
    root["姓名"] = "小美";
    root["年龄"] = 18;
    root["成绩"].append(99.6);
    root["成绩"].append(98);
    root["成绩"].append(47.2);
    Json_util::serialize(root, out);
    ILOG("%s", out.c_str());
    // 输出数据
    Json::Value val;
    Json_util::unserialize(out, val);
    std::cout << "姓名:" << val["姓名"].asCString() << std::endl;
    std::cout << "年龄:" << val["年龄"].asInt() << std::endl;
    for (int i = 0; i < val["成绩"].size(); i++)
    {
        std::cout << "成绩:" << val["成绩"][i].asFloat() << std::endl;
    }
}
void testStr()
{
    string s = ",,kkk,,aaa,bbb,cccc,,,,vvv,,,";
    vector<string> res;
    String_util::splits(s, ",", res);
    for (auto v : res)
    {
        ILOG("%s", v.c_str());
    }
}
void testFile()
{
    string filename = "./logger.hpp";
    string body;
    file_util::read(filename, body);
    cout << body << endl;
}
void testUserTable()
{
    user_table userdb(HOST, USER, PASSWORD, DB, PORT);
    Json::Value user;
    user["username"] = "ZhangsangSan";
    user["password"] = "12345678";
    // 注册
    // userdb.insert(user);

    // 登录
    // userdb.login(user);

    // 按名查找
    Json::Value val;
    userdb.select_name(val, "ZhangsangSan");

    // 按id查找
    int id = 1;
    userdb.select_id(val, id);

    // 赢家更新
    // userdb.win(id);
    // 输家更新
    userdb.lose(id);
}
void testOnline()
{
    online_manager om;
    wsserver_t::connection_ptr conn;
    om.enter_game_hall(1, conn);
    om.enter_game_room(2, conn);
    if (om.is_in_game_hall(1))
    {
        cout << "hall 1" << endl;
    }
    om.exit_game_hall(1);
    if (!om.is_in_game_hall(1))
    {
        cout << "not hall 1" << endl;
    }
    om.exit_game_room(2);

    om.get_conn_from_hall(1);
    om.get_conn_from_room(1);
}
void testRoom()
{
    user_table userdb(HOST, USER, PASSWORD, DB, PORT);
    online_manager om;
    //room r(11,&om,&userdb);
}
void testRoomManager()
{
    user_table userdb(HOST, USER, PASSWORD, DB, PORT);
    online_manager om;
    room_manager rm(&om,&userdb);
    room_ptr rp = rm.create_room(11,55);
}
void testSession()
{
    wsserver_t ws;
    session_manager sm(&ws);
    sm.create_session(1,LOGIN);
}
void testMatcher()
{   
    match_queue<int> mc;
}
void testMatcherManager()
{   
    
    user_table userdb(HOST, USER, PASSWORD, DB, PORT);
    online_manager om;
    room_manager rm(&om,&userdb);
    match_manager mc(&userdb,&rm,&om);
    
}
void testGobang()
{
    gobang_server gobang(HOST, USER, PASSWORD, DB, PORT);
    gobang.start(8080);
}
int main()
{
    // testLog();
    // testMySQL();
    // testJson();
    // testStr();
    // testFile();
    // testUserTable();
    // testOnline();
    // testRoom();
    // testRoomManager();
    // testSession();
    // testMatcher();
    // testMatcherManager();
    testGobang();
    return 0;
}